package heap

var primitiveTypes = map[string]string{
    "void":"V",
    "boolean":"Z",
    "byte":"B",
    "short":"S",
    "int":"I",
    "long":"J",
    "char":"C",
    "float":"F",
    "double":"D",
}
func getArrayClassName(className string) string {
    return "[" + toDescriptor(className)
}

func getComponentClassName(className string) string {
    if className[0] == '[' {
        compoentTypeDescriptor := className[1:]
        return toClassName(compoentTypeDescriptor)
    }
    panic("不是数组: " + className)
}

func toDescriptor(className string) string {
    if className[0] == '[' {
        return className
    }
    if d, ok := primitiveTypes[className]; ok {
        return d
    }
    return "L" + className + ";"
}

func toClassName(descriptor string) string {
    if descriptor[0] == '[' {
        return descriptor
    }

    if descriptor[0] == 'L' {
        return descriptor[1:len(descriptor) - 1]
    }
    for className, d := range primitiveTypes {
        if d == descriptor {
            return className
        }
    }
    panic("不合法的描述符号：" + descriptor)
}

